/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImageMergerUI.java
 *
 * Created on Jan 12, 2011, 6:02:33 AM
 */
package project.jpdftools.imagemerger;

import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.logging.Level;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import project.jpdftools.animation.AnimationWorker;
import project.jpdftools.constants.Const.MOVE_ITEM;
import project.jpdftools.imagemerger.actionlisteners.ListUpDownListener;
import project.jpdftools.imagemerger.thread.ImageMergerThread;
import project.jpdftools.managers.LocalizationManager;
import project.jpdftools.managers.LoggerManager;
import project.jpdftools.other.KeyValue;

/**
 *
 * @author Mido
 */
public class ImageMergerUI extends JFrame {

    private static boolean is_component_visible = false;
    private DefaultListModel default_model = new DefaultListModel();

    /**
     * Creates new form ImageMergerUI
     */
    public ImageMergerUI() {
        initComponents();

        // center the component
        project.jpdftools.toolkit.Toolkit.centerWindow(this, this.getHeight(), this.getWidth());

        // indicate that the frame is visible
        is_component_visible = true;

        // add action listeners to buttons
        bt_move_up.addActionListener(new ListUpDownListener(list_files_to_merge, default_model, MOVE_ITEM.move_up));
        bt_move_down.addActionListener(new ListUpDownListener(list_files_to_merge, default_model, MOVE_ITEM.move_down));
        LoggerManager.getLogger().log(Level.INFO, "Frame shown \"{0}\".", "ImageMergerUI");
    }

    public static boolean IsComponentVisible() {
        return is_component_visible;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bt_merge = new javax.swing.JButton();
        bt_cancel = new javax.swing.JButton();
        p_note = new javax.swing.JPanel();
        ta_info = new javax.swing.JTextArea();
        bt_info = new javax.swing.JButton();
        p_files_to_merge = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        list_files_to_merge = new javax.swing.JList(default_model);
        chb_compress_images = new javax.swing.JCheckBox();
        bt_add_and_browse = new javax.swing.JButton();
        bt_remove = new javax.swing.JButton();
        bt_move_up = new javax.swing.JButton();
        bt_move_down = new javax.swing.JButton();
        bt_remove_all = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        tf_title = new javax.swing.JTextField();
        l_subject = new javax.swing.JLabel();
        l_keywords = new javax.swing.JLabel();
        l_author = new javax.swing.JLabel();
        tf_subject = new javax.swing.JTextField();
        tf_author = new javax.swing.JTextField();
        l_title = new javax.swing.JLabel();
        tf_keywords = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_MERGE_IMAGE_FILES"));
        setIconImage(Toolkit.getDefaultToolkit().getImage("Data/Icons/Soft Scraps Icons/10.png"));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                ImageMergerUI.this.windowClosing(evt);
            }
        });

        bt_merge.setText(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_MERGE"));
        bt_merge.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_mergeActionPerformed(evt);
            }
        });

        bt_cancel.setText(LocalizationManager.getCurrent_resource().getString("CANCEL"));
        bt_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelActionPerformed(evt);
            }
        });

        p_note.setBorder(javax.swing.BorderFactory.createTitledBorder(null, LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_NOTE_PANEL_TITLE"), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Times New Roman", 1, 12), new java.awt.Color(0, 0, 255))); // NOI18N

        ta_info.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.background"));
        ta_info.setColumns(20);
        ta_info.setEditable(false);
        ta_info.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ta_info.setLineWrap(true);
        ta_info.setRows(5);
        ta_info.setText(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_INFO"));
        ta_info.setAutoscrolls(false);
        ta_info.setOpaque(false);
        ta_info.setRequestFocusEnabled(false);

        bt_info.setBorder(null);
        bt_info.setBorderPainted(false);
        bt_info.setContentAreaFilled(false);
        bt_info.setDefaultCapable(false);
        bt_info.setFocusPainted(false);
        bt_info.setFocusable(false);
        bt_info.setRequestFocusEnabled(false);
        bt_info.setRolloverEnabled(false);

        javax.swing.GroupLayout p_noteLayout = new javax.swing.GroupLayout(p_note);
        p_note.setLayout(p_noteLayout);
        p_noteLayout.setHorizontalGroup(
            p_noteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_noteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bt_info, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ta_info)
                .addContainerGap())
        );
        p_noteLayout.setVerticalGroup(
            p_noteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_noteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p_noteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ta_info, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(bt_info, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        bt_info.setIcon(new ImageIcon("Data/Icons/Basic/Information-icon.png"));

        p_files_to_merge.setBorder(javax.swing.BorderFactory.createTitledBorder(null, LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_FILES_TO_MERGE"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 12), new java.awt.Color(0, 0, 255))); // NOI18N

        list_files_to_merge.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        list_files_to_merge.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                list_files_to_mergeKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(list_files_to_merge);

        chb_compress_images.setText(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_COMPRESS_IMAGES"));

        javax.swing.GroupLayout p_files_to_mergeLayout = new javax.swing.GroupLayout(p_files_to_merge);
        p_files_to_merge.setLayout(p_files_to_mergeLayout);
        p_files_to_mergeLayout.setHorizontalGroup(
            p_files_to_mergeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_files_to_mergeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p_files_to_mergeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chb_compress_images)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 479, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        p_files_to_mergeLayout.setVerticalGroup(
            p_files_to_mergeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_files_to_mergeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chb_compress_images)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bt_add_and_browse.setIcon(new ImageIcon("Data/Icons/Basic/Document-Add-icon.png"));
        bt_add_and_browse.setText(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_ADD_FILE"));
        bt_add_and_browse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_add_and_browseActionPerformed(evt);
            }
        });

        bt_remove.setIcon(new ImageIcon("Data/Icons/Basic/page-remove-icon.png"));
        bt_remove.setText(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_REMOVE"));
        bt_remove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_removeActionPerformed(evt);
            }
        });

        bt_move_up.setIcon(new ImageIcon("Data/Icons/Basic/Button-Up-icon.png"));
        bt_move_up.setText(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_MOVE_UP"));

        bt_move_down.setIcon(new ImageIcon("Data/Icons/Basic/Button-Down-icon.png"));
        bt_move_down.setText(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_MOVE_DOWN"));

        bt_remove_all.setIcon(new ImageIcon("Data/Icons/Basic/remove-icon.png"));
        bt_remove_all.setText(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_REMOVE_ALL"));
        bt_remove_all.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_remove_allActionPerformed(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, LocalizationManager.getCurrent_resource().getString("MAIN_MENU_DOCUMENT_INFO_TITLE"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 12), new java.awt.Color(0, 0, 255))); // NOI18N

        l_subject.setText("Subject:");

        l_keywords.setText("Keywords:");

        l_author.setText("Author:");

        l_title.setText("Title:");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(l_title)
                    .addComponent(l_subject))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_title, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_subject, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(l_author)
                    .addComponent(l_keywords))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_author)
                    .addComponent(tf_keywords))
                .addGap(108, 108, 108))
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {tf_subject, tf_title});

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {tf_author, tf_keywords});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(l_title)
                            .addComponent(tf_author, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(l_author)
                            .addComponent(tf_title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                    .addComponent(tf_subject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(l_subject)))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(tf_keywords, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.CENTER, jPanel4Layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(l_keywords)))
                .addContainerGap())
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {tf_subject, tf_title});

        jPanel4Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {tf_author, tf_keywords});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(p_files_to_merge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(bt_add_and_browse, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(bt_remove, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(bt_remove_all, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(bt_move_up, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(bt_move_down, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(p_note, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(9, 9, 9))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(bt_merge)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_cancel)
                        .addContainerGap())))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jPanel4, p_note});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(p_note, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(p_files_to_merge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(bt_add_and_browse)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_remove)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_remove_all)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_move_up)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_move_down)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_cancel)
                    .addComponent(bt_merge))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelActionPerformed
        // close the frame
        this.dispose();
        // indicate that the frame is hidden
        is_component_visible = false;
        LoggerManager.getLogger().log(Level.INFO, "Frame hidden \"{0}\".", "ImageMergerUI");
    }//GEN-LAST:event_bt_cancelActionPerformed

    private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
        bt_cancelActionPerformed(null);
    }//GEN-LAST:event_windowClosing

    private void bt_add_and_browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_add_and_browseActionPerformed
        // choose file location
        JFileChooser file_chooser = new JFileChooser();

        file_chooser.setDialogTitle(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_FILE_CHOOSER_TITLE"));
        file_chooser.setMultiSelectionEnabled(true);
        file_chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        file_chooser.setFileFilter(new FileNameExtensionFilter("Image files(*.jpg, *.jpeg, *.bmp, *.png, *.gif, *.tif, *.tiff)",
                "jpg", "jpeg", "bmp", "png", "gif", "tif", "tiff"));

        int returnVal = file_chooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File[] selected_files = file_chooser.getSelectedFiles();
            for (int i = 0; i < selected_files.length; i++) {
                String file_name = selected_files[i].getAbsolutePath().toLowerCase();
                // check for valid extensions and refuse others
                if (file_name.endsWith("bmp") == true || file_name.endsWith("png") == true || file_name.endsWith("jpeg") == true
                        || file_name.endsWith("jpg") == true || file_name.endsWith("gif") == true
                        || file_name.endsWith("tiff") == true || file_name.endsWith("tif") == true) {
                    // add the file to the model
                    default_model.addElement(new KeyValue(selected_files[i].getAbsolutePath(), selected_files[i].getName()));
                }
            }
        }
    }//GEN-LAST:event_bt_add_and_browseActionPerformed

    private void bt_removeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_removeActionPerformed
        // make sure that there is a file selected
        if (list_files_to_merge.getSelectedIndex() == -1) {
            // show an error message
            JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_NO_FILE_SELECTED"),
                    LocalizationManager.getCurrent_resource().getString("ERROR"), 0);
            return;
        }

        // remove the selected file from the list
        default_model.remove(list_files_to_merge.getSelectedIndex());
    }//GEN-LAST:event_bt_removeActionPerformed

    private void bt_mergeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_mergeActionPerformed
        int list_size = default_model.getSize();
        // check if there is no files to merge
        if (list_size == 0) {
            // show error message
            JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_NO_FILES"),
                    LocalizationManager.getCurrent_resource().getString("ERROR"), 0);
            return;
        }

        try {
            // Resulting pdf location
            JFileChooser file_chooser = new JFileChooser();
            if (file_chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
                // create a thread to merge the images
                ImageMergerThread thread = new ImageMergerThread(new AnimationWorker(LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_MERGING_IMAGES")), chb_compress_images.isSelected(), tf_title.getText(),
                        tf_author.getText(), tf_subject.getText(), tf_keywords.getText(), file_chooser.getSelectedFile(), default_model);
                // start the thread
                thread.start();
            }
        } catch (Exception ex) {
            // show error message
            JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_FAIL"),
                    LocalizationManager.getCurrent_resource().getString("ERROR"), 0);
            LoggerManager.getLogger().log(Level.SEVERE, "Merging images failed. Message = {0}", project.jpdftools.toolkit.Toolkit.getStackTraceAsString(ex.getCause()));
        }
    }//GEN-LAST:event_bt_mergeActionPerformed

    private void list_files_to_mergeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_list_files_to_mergeKeyPressed
        // check if the user pressed delete key
        if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
            bt_removeActionPerformed(null);
        }
    }//GEN-LAST:event_list_files_to_mergeKeyPressed

    private void bt_remove_allActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_remove_allActionPerformed
        // make sure that there are some files inserted
        if (default_model.isEmpty() == true) {
            // show an error message
            JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("MERGE_FILES_PANEL_NO_FILES_TO_REMOVE"),
                    LocalizationManager.getCurrent_resource().getString("ERROR"), 0);
            return;
        }

        // remove all files from the list
        while (default_model.isEmpty() == false) {
            default_model.remove(0);
        }
    }//GEN-LAST:event_bt_remove_allActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_add_and_browse;
    private javax.swing.JButton bt_cancel;
    private javax.swing.JButton bt_info;
    private javax.swing.JButton bt_merge;
    private javax.swing.JButton bt_move_down;
    private javax.swing.JButton bt_move_up;
    private javax.swing.JButton bt_remove;
    private javax.swing.JButton bt_remove_all;
    private javax.swing.JCheckBox chb_compress_images;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel l_author;
    private javax.swing.JLabel l_keywords;
    private javax.swing.JLabel l_subject;
    private javax.swing.JLabel l_title;
    private javax.swing.JList list_files_to_merge;
    private javax.swing.JPanel p_files_to_merge;
    private javax.swing.JPanel p_note;
    private javax.swing.JTextArea ta_info;
    private javax.swing.JTextField tf_author;
    private javax.swing.JTextField tf_keywords;
    private javax.swing.JTextField tf_subject;
    private javax.swing.JTextField tf_title;
    // End of variables declaration//GEN-END:variables
}
